﻿using System;
using System.Linq;
using Common.Dao;
using log4net;
using Common.Model;
using Spider.Spider;

namespace Spider.Script
{
    public class GszScript
    {
        
        private static readonly ILog Log = LogManager.GetLogger(typeof(GszScript));
        
        public static void Run()
        {
            Log.Info("GszScript start");
            var gszSpider = new GszSpider();

            var newses = gszSpider.GetNews(GszDao.GetLastNews().CrawlingTime.AddDays(-1), DateTime.Now);
            var list = newses.Select(m => new GszNews
            {
                Content = m.Abs,
                ContentId = m.ContentId,
                CrawlingTime = DateTime.Now,
                Stock = m.Stocks,
                Title = m.Title

            }).ToList();
            
            list.ForEach(m =>
            {
                Log.Info("股票:"+m.Stock);
                Log.Info("预案:"+m.Content);
            });
            
            GszDao.BatchSaveNews(list);
            
            Log.Info("GszScript end");
        }
    }
}